package etxt2db.annotators;

import java.io.IOException;
import java.io.Serializable;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import edu.cmu.minorthird.text.Annotator;
import edu.cmu.minorthird.text.MonotonicTextLabels;
import edu.cmu.minorthird.text.Span;
import edu.cmu.minorthird.text.TextLabels;
import edu.cmu.minorthird.text.learn.SpanFeatureExtractor;
import edu.cmu.minorthird.ui.Recommended;
import etxt2db.api.ClassificationModel;

public class MEMMClassificationModel extends ClassificationModel implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = -1949145419715812890L;
	protected Set<Set<String>> compatibleAttributes = new HashSet<Set<String>>();
	Annotator ann;
	
	public MEMMClassificationModel(TextLabels trainingFile, List<String> attributes,Set<Set<String>> compatibleAttributes) throws ParseException, IOException{
		this(trainingFile, attributes, new Recommended.TokenFE(),compatibleAttributes);
	}
	
	public MEMMClassificationModel(TextLabels trainingFile, List<String> att, SpanFeatureExtractor tokenFE,Set<Set<String>> compatibleAttributes) throws ParseException, IOException{
		this.compatibleAttributes = compatibleAttributes;
		ann = doTraining(trainingFile,att, tokenFE);
	}
	
	
	protected Annotator doTraining (TextLabels labels, List<String> attributes,SpanFeatureExtractor tokenFE) throws IOException, ParseException{
		OverlapedTagClassificationModel result = new OverlapedTagClassificationModel();
		for(Set<String> setStr : compatibleAttributes){
			List<String> listStr = new ArrayList<String>(setStr);
			// Train the Annotator
			result.addAnnotator(new MalletMEMMClassificationModel(labels,listStr,tokenFE));
		}
		return result;
	}
	
	public void annotate(MonotonicTextLabels arg0) {
		ann.annotate(arg0);	
	}

	public TextLabels annotatedCopy(TextLabels arg0) {
		return ann.annotatedCopy(arg0);
	}

	public String explainAnnotation(TextLabels arg0, Span arg1) {
		return null;
	}

}
